﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace BaseHelper.Encrypt
{
    public class HmacHelper
    {
        public static string Encrypt(string toEncrypt,string key)
        {
            var encoding = new System.Text.ASCIIEncoding();
            byte[] keyByte = encoding.GetBytes(key);
            byte[] messageBytes = encoding.GetBytes(toEncrypt);
            using (var hmacsha256 = new HMACSHA256(keyByte))
            {
                byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);

                return ToolsHelper.BytesToStr(hashmessage).ToLower();
            }
        }
    }
}
